package com.dw.dwdzcommerce.view.operate;

import com.dw.dwdzcommerce.R;
import com.dw.dwdzcommerce.test.TestFragmentMap;
import com.dw.dwdzcommerce.view.mainContent.MainContentFragment;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;

public class OperateContentLayout {

	private MainContentFragment mMainContentFragment;
	private TestFragmentMap maptest;
	private OperateActivity mActivity;

	public void initModule(OperateActivity activity) {
		mActivity = activity;
		initFragment();
	}

	private void initFragment() {
		mMainContentFragment = new MainContentFragment();
		maptest = new TestFragmentMap();
		addFragment(mMainContentFragment);
		addFragment(maptest);

	}

	private void addFragment(Fragment fragment) {
		FragmentTransaction transaction = mActivity.getSupportFragmentManager().beginTransaction();
		boolean added = fragment.isAdded();
		if (added) {
			return;
		}
		transaction.add(R.id.activity_operate_content_container, fragment);
		transaction.commit();
	}

	public void selectMainFragment() {
		showFragment(mMainContentFragment);
	}

	public void selectMapFragment() {
		showFragment(maptest);
	}

	public void selectMineFragment() {
		showFragment(mMainContentFragment);
	}

	private void showFragment(Fragment fragment) {
		FragmentTransaction transaction = mActivity.getSupportFragmentManager().beginTransaction();
		hideAll(transaction);
		transaction.show(fragment);
		transaction.commit();
	}

	private void hideAll(FragmentTransaction transaction) {
		transaction.hide(mMainContentFragment);
		transaction.hide(maptest);

	}


}
